use warp::Filter;

use crate::info;

pub mod status;
pub mod basic;
pub mod cluster;

pub async fn start_server(ip: [u8; 4], port: u16) {
	info!(format!("starting server at: {:?}:{}", ip, port));
	warp::serve(
		warp::path!()
		.and(warp::header("Authorization"))
		.map(status::status)
		.or(
			warp::path!("clusters")
			.and(warp::header("Authorization"))
			.map(cluster::clusters)
		).or(
			warp::path!("diff" / String / String)
			.and(warp::header("Authorization"))
			.map(cluster::cluster_diff)
		).or(
			warp::path!("update" / String / String)
			.and(warp::header("Authorization"))
			.map(cluster::cluster_update)
		).or(
			warp::path!("latest" / String)
			.and(warp::header("Authorization"))
			.map(cluster::cluster_latest)
		)
	).run((ip, port)).await;
}
